package BBDD;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import DAO.Grupo_ModuloDAO;
import DAO.Grupo_Modulo_AlumnoDAO;

public class ManageGrupoModulo {
	private Connection conn;
	private Statement pstmt;
	private ResultSet rs;
	private String query;
	private ManageDB abreConn;
	private Vector<Grupo_ModuloDAO> grupoModulo = new Vector<Grupo_ModuloDAO>();

	public ManageGrupoModulo() {
		abreConn = new ManageDB();
		conn = abreConn.getConnection();
	
		abreConn.OpenDB();
	}

	public void loadDataGrupoModulo(String query) {
		this.query = query;
		conn = abreConn.getConnection();
		
		try {
			pstmt = conn.createStatement();
			rs = pstmt.executeQuery(query);		
			
			while (rs.next()) {
				int idGrupo = rs.getInt(1);
				int idModulo  = rs.getInt(2);
				int idProfesor = rs.getInt(3);
				setGrupoModulo(new Grupo_ModuloDAO(idGrupo, idModulo, idProfesor));

			}

		} catch (SQLException ex) {
			Logger.getLogger(ManageGrupoModulo.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {
			try {
				rs.close();
				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}

		}
	}

	public void updateGrupoModulo(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {

			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageAlumno.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {

				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public void deleteGrupoModulo(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {

			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageAlumno.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {

				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public String getOldQuery() {
		return query;
	}

	public Vector<Grupo_ModuloDAO> getGrupoModulo() {
		return grupoModulo;
	}

	public void setGrupoModulo(Grupo_ModuloDAO grupoModulo) {
		this.grupoModulo.add(grupoModulo);
	}
}
